<?php
/**
 * Created by PhpStorm.
 * User: 王文凡<787802868@qq.com>
 * Date: 2016/9/27 0027
 * Time: 14:54
 */

namespace Common\Model;
use Think\Model;

class GradeModel extends Model
{
    protected $_validate = array(
        array('class_name','require', '年级名称必须填写'),
        array('class_name','','年级名称已经存在！',0,'unique',1),
        array('uid','require', '负责人必须填写'),
    );

    /**新增年级
     * @return mixed
     */
    public function data_into(){
        if(!$this->create()){
            $arr['state']='error';
            $arr['info']=$this->getError();
        }else{
            $_POST['create_time']=time();
            if($gid=$this->add($_POST)){
                $uid=I('post.uid');//负责人
                $gid .=',';
                $sql="UPDATE sc_member SET gid=CONCAT(gid,'{$gid}')WHERE uid=$uid";
                $re=M()->execute($sql);
                $arr['state']='success';
                $arr['info']='新增成功';
            }else{
                $arr['state']='error';
                $arr['info']='新增失败';
            }
        }
        return $arr;
    }
}